/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.deployment.figure;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MidpointLocator;
import org.eclipse.draw2d.PolylineDecoration;
import org.eclipse.draw2d.PositionConstants;

import com.cea.papyrus.core.figures.connection.EdgeFigure;

/**
 * Defines the view of a deployment.
 * 
 * @author Gilles Cannenterre
 * @since 22 janv. 07
 */
public class DeploymentFigure extends EdgeFigure {
	
	/**
	 * The dashes.
	 */
	protected int[] dashes =new int[10];
	
	/**
	 * The label.
	 */
	protected Label label;
	
	/**
	 * The Constructor.
	 */
	public DeploymentFigure() {
		super();
		PolylineDecoration dec = new PolylineDecoration();
		dec.setScale( 15, 5);
		dec.setLineWidth(1);
		// Arrow at source endpoint
		setSourceDecoration(dec);
		 // Line drawing style
		setLineStyle(Graphics.LINE_CUSTOM);

		label = new Label();
		label.setOpaque(true);
		MidpointLocator locator = new MidpointLocator(this, 0);
		locator.setRelativePosition(PositionConstants.NORTH); 
		add (label, locator);
		setLineWidth(1);
		for (int i=0;i<10;i++) {
			dashes[i]=5;
		}	
	}
	
	/**
	 * Setname.
	 * 
	 * @param text the text
	 */
	public void setname(String text){
		label.setText(text);
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.draw2d.Shape#paintFigure(org.eclipse.draw2d.Graphics)
	 */
	/**
	 * 
	 * 
	 * @param graphics 
	 */
	@Override
	public void paintFigure(Graphics graphics) {
		graphics.pushState();
		if (dashes != null) {
			graphics.setLineDash(dashes);
		}
		
		super.paintFigure(graphics);
		if (img!=null){
		super.FillFigure(graphics);}
		graphics.popState();
	}
}